home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Metafiles / CreateMetafileReload / CreateMetafileReload.cs next >
Encoding:
Text File  |  2001-01-15  |  1.7 KB  |  55 lines

  1. //---------------------------------------------------
  2. // CreateMetafileReload.cs ⌐ 2001 by Charles Petzold
  3. //---------------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Imaging;
  7. using System.IO;
  8. using System.Windows.Forms;
  9.  
  10. class CreateMetafileReload: PrintableForm
  11. {
  12.      const string strMetafile = "CreateMetafileReload.emf";
  13.  
  14.      public new static void Main()
  15.      {
  16.           Application.Run(new CreateMetafileReload());
  17.      }
  18.      public CreateMetafileReload()
  19.      {
  20.           Text = "Create Metafile (Reload)";
  21.  
  22.           if (!File.Exists(strMetafile))
  23.           {
  24.                     // Create the metafile.
  25.  
  26.                Graphics grfx = CreateGraphics();
  27.                IntPtr ipHdc = grfx.GetHdc();
  28.  
  29.                Metafile mf = new Metafile(strMetafile, ipHdc); 
  30.  
  31.                grfx.ReleaseHdc(ipHdc);
  32.                grfx.Dispose();
  33.  
  34.                     // Draw on the metafile.
  35.  
  36.                grfx = Graphics.FromImage(mf);
  37.  
  38.                grfx.FillEllipse(Brushes.Gray, 0, 0, 100, 100);
  39.                grfx.DrawEllipse(Pens.Black, 0, 0, 100, 100);
  40.                grfx.FillEllipse(Brushes.Blue, 20, 20, 20, 20);
  41.                grfx.FillEllipse(Brushes.Blue, 60, 20, 20, 20);
  42.                grfx.DrawArc(new Pen(Color.Red, 10), 20, 20, 60, 60, 30, 120);
  43.                grfx.Dispose();
  44.           }
  45.      }
  46.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  47.      {
  48.           Metafile mf = new Metafile(strMetafile);
  49.  
  50.           for (int y = 0; y < cy; y += mf.Height)
  51.           for (int x = 0; x < cx; x += mf.Width)
  52.                grfx.DrawImage(mf, x, y, mf.Width, mf.Height);
  53.      }
  54. }
  55.